/*
 * PlainParagraph.cpp
 *
 *  Created on: Sep 13, 2012
 *      Author: sbellus
 */

#include "PlainParagraph.h"
#include "Text.h"
#include "PlainSmiley.h"
#include <Printer.h>

#include <PrinterLibrary/Printer.h>

PlainParagraph::PlainParagraph()
{
}

PlainParagraph::~PlainParagraph()
{
   std::vector<Printable*>::iterator printable = printables.begin();

   while (printable != printables.end())
   {
      delete (*printable);
      printable++;
   }
}

Text& PlainParagraph::AddText()
{
   Text* t = new Text();
   printables.push_back(t);
   return *t;
}

Smiley& PlainParagraph::AddSmiley()
{
   Smiley* s = new PlainSmiley();
   printables.push_back(s);
   return *s;
}

void PlainParagraph::PrintOn(Printer& printer)
{
   std::vector<Printable*>::iterator printable = printables.begin();

   while (printable != printables.end())
   {
      (*printable)->PrintOn(printer);

      printable++;

      if (printable != printables.end())
      {
         printer.Print(" ");
      }
   }

   printer.Print("\n");
}
